//
//  LYTitleView.swift
//  LYOnlineBanking
//
//  Created by 李永彬 on 2025/7/20.
//

import UIKit
import SnapKit

class LYTitleView: UIView {
    
    // MARK: - UI Elements
    private let backgroundImageView: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFill
        iv.clipsToBounds = true
        return iv
    }()
    
    private let titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14, weight: .regular)
        label.textAlignment = .left
        return label
    }()
    
    // MARK: - Properties
    var title: String? {
        didSet {
            titleLabel.text = title  // 现在会在初始化时执行
        }
    }
    
    var titleColor: UIColor = UIColor(hex: "#000000") {
        didSet {
            titleLabel.textColor = titleColor
        }
    }
    
    var backgroundImage: UIImage? {
        didSet {
            backgroundImageView.image = backgroundImage
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupUI()
    }
    
    // MARK: - Setup
    private func setupUI() {
        addSubview(backgroundImageView)
        addSubview(titleLabel)
        
        backgroundImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.leading.trailing.equalToSuperview().inset(16)
        }
    }
}
